<?php
require_once('../phplib/include.inc.php');

class ViewLog extends PageBase{
	public function Ini(){
		PageBase::RequireLogin();
		$this->GetLogs();
		$this->GetUsers();
	}
	public function GetUsers(){
		/* @var $db DbMySQL */
		$db = getDb();
		$db->connect();
		$users = $db->fetch("SELECT * FROM user_t");
		$this->assign('users',$users);
	}
	public function GetLogs(){
		$page = intval($_REQUEST['page']);
		$uid = intval($_REQUEST['uid']);
		$ust = " l.uid>{0} ";
		if($uid > 0) $ust = " l.uid={0} ";
		/* @var $db DbMySQL */
		$arr = array($uid);
		$sql = "SELECT l.*,u.uname FROM log_t AS l LEFT JOIN user_t AS u ON l.uid=u.uid WHERE $ust ";
		if(isset($_REQUEST['stime'])){
			$t = " AND l.logtime >{1} AND l.logtime<{2} ";
			$sql .= $t;
			$arr[1] = $_REQUEST['stime'];
			$arr[2] = $_REQUEST['etime'];
		}
		$sql .= ' ORDER BY l.logtime DESC';
		$db = getDb();
		$db->connect();
		$pageinfo = array();
		$logs = $db->fetch_paged($sql,$page,20,$pageinfo,$arr);
		$this->assign('logs',$logs);
		$this->assign('pageinfo',$pageinfo);
		$pages = array();
		for($i=0;$i<$pageinfo['pageCount'];$i++){
			$pages[$i] = $i + 1;
		}
		$this->assign('pages',$pages);
	}
}
$viewlog = new ViewLog("file:".dirname(__FILE__)."/../home/viewlog.tpl.html");
$viewlog->display();
?>